Option Strict On

Imports System.Drawing
Imports System.Windows.Forms

Namespace xpComponent.Form
    Public Class xpCheckBox
        Inherits System.Windows.Forms.CheckBox
        Implements xpComponent.Form.IDisabled

        Private mblnEnabled As Boolean = True
        Private mclrBackColorDisabled As System.Drawing.Color = System.Drawing.Color.Gainsboro
        Private mclrForeColorDisabled As System.Drawing.Color = System.Drawing.SystemColors.ControlText

        Public Property BackColorDisabled() As System.Drawing.Color Implements xpComponent.Form.IDisabled.BackColorDisabled
            Get
                Return mclrBackColorDisabled
            End Get
            Set(ByVal Value As System.Drawing.Color)
                mclrBackColorDisabled = Value
            End Set
        End Property

        Public Property ForeColorDisabled() As System.Drawing.Color Implements xpComponent.Form.IDisabled.ForeColorDisabled
            Get
                Return mclrForeColorDisabled
            End Get
            Set(ByVal Value As System.Drawing.Color)
                mclrForeColorDisabled = Value
            End Set
        End Property

        Public Shadows Property Enabled() As Boolean
            Get
                Return mblnEnabled
            End Get
            Set(ByVal Value As Boolean)
                'Keeps the current Back/Fore color
                Static sclrBackColor As System.Drawing.Color
                Static sclrForeColor As System.Drawing.Color
                Static sblnTabStop As Boolean

                If sclrBackColor.IsEmpty Then
                    sclrBackColor = Me.BackColor
                    sclrForeColor = Me.ForeColor
                    sblnTabStop = Me.TabStop
                End If

                'Stop looping in itself
                Static sblnIsProcessing As Boolean
                If sblnIsProcessing Then Exit Property
                sblnIsProcessing = True

                mblnEnabled = Value
                Me.Enabled = True
                If mblnEnabled Then
                    Me.BackColor = sclrBackColor
                    Me.ForeColor = sclrForeColor
                    Me.AutoCheck = True
                    Me.TabStop = sblnTabStop
                Else
                    Me.BackColor = Me.BackColorDisabled
                    Me.ForeColor = Me.ForeColorDisabled
                    Me.AutoCheck = False
                    Me.TabStop = False
                End If
                Me.Invalidate()

                sblnIsProcessing = False
            End Set
        End Property
    End Class
End Namespace